package goods;

import java.util.ArrayList;
import java.util.Arrays;

public class Goods {
    private String name;
    private double price;
    private ArrayList<String> label = new ArrayList<>();
    private long amount;
    private long id;

    public Goods(String name, String price, String str, String amount, String id) {
        this.name = name;
        this.price = Double.parseDouble(price);
        String[] temp = str.split("、");
        label.addAll(Arrays.asList(temp));
        this.amount = Long.parseLong(amount);
        this.id = Long.parseLong(id);
    }

    public Goods(Goods goods) {
        this.name = goods.getName();
        this.price = goods.getPrice();
        this.label = goods.getLabel();
        this.amount = goods.getAmount();
        this.id = goods.getId();

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public ArrayList<String> getLabel() {
        return label;
    }
    public String toStringLabel(){
        StringBuilder str = new StringBuilder();
        int flag = 0;
        for (String s:label) {
            if(flag == 0){
                str.append(s);
                flag=1;
            }else
                str.append("、"+s);
        }
        str.append(" ");
        return new String(str);
    }
    public void setLabel(ArrayList<String> label) {
        this.label = label;
    }

    public long getAmount() {
        return amount;
    }

    public void setAmount(long amount) {
        this.amount = amount;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Override
    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append(name).append(" ").append(price).append(" ");
        for(int i = 0 ; i < label.size() ; i ++) {
            if(i == 0 ) {
                str.append(label.get(i));
            }else {
                str.append("、").append(label.get(i));
            }
        }
        str.append(" ").append(amount).append(" ").append(id).append("\n");
        return new String(str);
    }
}
